package com.shycloud.mido.task.job;

import com.shycloud.mido.common.core.constant.SecurityConstants;
import com.shycloud.mido.member.api.feign.RemoteMemberService;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shycloud.mido.homework.api.feign.HomeworkFeignService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestHeader;

@Service
@Slf4j
public class BatchJob {

	@Autowired
	private HomeworkFeignService homeworkFeignService;

	@Autowired
	private RemoteMemberService remoteMemberService;

	@XxlJob("execBatchOss")
	public void execBatchOss() throws Exception {
		String param = XxlJobHelper.getJobParam();
		log.info("接收调度中心参数...[{}]", param);
		log.info("execBatchOss execute...");

		String[] split = param.split(",");

		try {
			homeworkFeignService
					.deleteRecordingSources(split[0], split[1], SecurityConstants.FROM_IN);
			XxlJobHelper.log("execBatchOss execute Success...");
			XxlJobHelper.handleSuccess("execBatchOss 执行成功参数：" + param);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("execBatchOss execute Fail ...", e);
			XxlJobHelper.log("execBatchOss execute Fail...");
			XxlJobHelper.handleFail("execBatchOss 执行失败参数：" + param + ",错误：" + e.getMessage());
		}
	}

	@XxlJob("batchAliTradePay")
	public void batchAliTradePay() {

		try {
			remoteMemberService.batchAliTradePay(SecurityConstants.FROM_IN);
			XxlJobHelper.log("execBatchOss execute Success...");
			XxlJobHelper.handleSuccess("batchAliTradePay 执行成功");
		} catch (Exception e) {
			e.printStackTrace();
			log.error("batchAliTradePay execute Fail ...", e);
			XxlJobHelper.log("batchAliTradePay execute Fail...");
			XxlJobHelper.handleFail("batchAliTradePay 执行失败,错误：" + e.getMessage());
		}

	}

	@XxlJob("batchAddMemberMaster")
	public void batchAddMemberMaster() {
		try {
			remoteMemberService.batchAddMemberMaster(SecurityConstants.FROM_IN);
			XxlJobHelper.log("batchAddMemberMaster execute Success...");
			XxlJobHelper.handleSuccess("batchAddMemberMaster 执行成功");
		} catch (Exception e) {
			e.printStackTrace();
			log.error("batchAddMemberMaster execute Fail ...", e);
			XxlJobHelper.log("batchAddMemberMaster execute Fail...");
			XxlJobHelper.handleFail("batchAddMemberMaster 执行失败,错误：" + e.getMessage());
		}
	}

}
